package com.example.day01_weather.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.day01_weather.R;
import com.example.day01_weather.bean.Station_listBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */
public class Station_List_City_Adapter extends RecyclerView.Adapter<Station_List_City_Adapter.ViewHolder> {
    private ArrayList<Station_listBean.DataBean> list;
    private Context context;
    private Station_listAdapter.OnItemClickListener onItemClickListener;

    public Station_List_City_Adapter(ArrayList<Station_listBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }


    public void setOnItemClickListener(Station_listAdapter.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onItemClick(int position);
    }

    @NonNull
    @Override
    public Station_List_City_Adapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.qie, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Station_List_City_Adapter.ViewHolder holder, int position) {
        holder.tv.setText(list.get(position).getStation());
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onItemClickListener!=null){
                    onItemClickListener.onItemClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static
    class ViewHolder extends Adapter2.ViewHolder {
        @BindView(R.id.TextView_t1)
        TextView tv;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
